package com.tqw.chd.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author Alex
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    //以后操作数据表的时候 会自动填充时间
    @Override
    public void insertFill(MetaObject metaObject) {
        Date date = new Date();
        this.setFieldValByName("created_time", date, metaObject);
        this.setFieldValByName("updated_time", date, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updated", new Date(), metaObject);
    }


}
